
The abstract keyword is used to create abstract classes. Abstract class can contain a regular method and also abstract method. When abstract class contain an abstract method then it can’t implementation, its just define. When the abstract class inherit the regular class then the regular class responsible to implementation the all abstract member of the abstract class also must and should use the override key word on the method. If parent and child class both are abstract then it can’t mandatory to implementation.
Note: Abstract class can’t be sealed key word and abstract class can’t create instance like interface.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using testForClass1;
namespace testFor
{
public abstract class Name
{
public abstract void PrintName();
}
public class Program : Name
{
public override void PrintName()
{
Console.WriteLine("Farhan Sakib Jesy");
}
static void Main(string[] args)
{
Program obj = new Program();
obj.PrintName();
Console.Read();
}
}
}
In this code we can see the Name class is abstract and also PrintName method is abstract so this method body is not defined. When program class inherit the abstract Name class then it implemented also use override key word. Now under Main method we create program class instance and Called the PrintName method.